From 22548785b03e32cc862847f4a0d2ae747c6e2d26 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 11 Jun 2023 08:06:14 -0400 Subject: [PATCH] atcontext: Update name computation Implement this sentence from the "Accessible Name and Description Computation 1.2" spec: If the root node's role prohibits naming, return the empty string (""). See https://www.w3.org/TR/accname-1.2/ --- gtk/gtkatcontext.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gtk/gtkatcontext.c b/gtk/gtkatcontext.c index 7db5c95fe7..d12a5be9bd 100644 --- a/gtk/gtkatcontext.c +++ b/gtk/gtkatcontext.c @@ -1150,6 +1150,13 @@ gtk_at_context_get_description_accumulate (GtkATContext *self, } } +static GtkAccessibleRole name_forbidden[] = { + GTK_ACCESSIBLE_ROLE_CAPTION, + GTK_ACCESSIBLE_ROLE_GENERIC, + GTK_ACCESSIBLE_ROLE_PRESENTATION, + GTK_ACCESSIBLE_ROLE_NONE, +}; + /*< private > * gtk_at_context_get_name: * @self: a `GtkATContext` @@ -1165,6 +1172,12 @@ gtk_at_context_get_name (GtkATContext *self) { g_return_val_if_fail (GTK_IS_AT_CONTEXT (self), NULL); + for (unsigned int i = 0; i < G_N_ELEMENTS (name_forbidden); i++) + { + if (self->accessible_role == name_forbidden[i]) + return g_strdup (""); + } + GPtrArray *names = g_ptr_array_new (); gtk_at_context_get_name_accumulate (self, names, TRUE); @@ -1204,6 +1217,12 @@ gtk_at_context_get_description (GtkATContext *self) { g_return_val_if_fail (GTK_IS_AT_CONTEXT (self), NULL); + for (unsigned int i = 0; i < G_N_ELEMENTS (name_forbidden); i++) + { + if (self->accessible_role == name_forbidden[i]) + return g_strdup (""); + } + GPtrArray *names = g_ptr_array_new (); gtk_at_context_get_description_accumulate (self, names, TRUE); -- 2.30.2